#include "Player.h"
#include <assert.h>
#include <iostream>
#include "Advisor.h"
Player::Player()
{  
  ai = NULL;
  owner = NULL;  //how about owns what vassals
  address = "";
  warFlag = false;
  maxHandSize = 3;
  moveCard = NULL;
  hunger = 0;
  moveFeedNumber = 0;
}

//Gets~~~~~~~~~~~~~~~~~~~~~~~
Deck* Player::getHand()
{
  return &hand;
}
vector<Player*> Player::getVassals()
{
  return vassals;
}
bool Player::getIsVassal()
{
  return getOwner() != NULL;
}
Player* Player::getOwner()
{
  return owner;
}
bool Player::getWarFlag()
{
  return warFlag;
}
string Player::getAddress()
{
  return address;
}
Deck* Player::getArmy(){
  return &army;
}
Card* Player::getMoveCard()
{
  if(getHand()->size() != 0){
    if(ai == NULL) return moveCard;
    return ai->whichCard();
  }
  return NULL;
}
int Player::getFeedNumber(){
  return moveFeedNumber;
}
int Player::getMaxHandSize(){
  return maxHandSize;
}
vector<Player*> Player::getFeedVassal()
{
  return moveFeedVassals;
}
int Player::getHunger()
{
  return hunger;
}


//Sets~~~~~~~~~~~~~~~~~~~~
void Player::setOwner(Player* czar)
{
  owner = czar;
}
void Player::setAdvisor(Advisor* advisor)
{
  ai = advisor;
}
void Player::setAddress(string _address)
{
  address = _address;
}
void Player::setMoveCard(Card* card)
{
  if(getHand()->size() != 0){
     moveCard = card;
  }
}
void Player::setMoveFeed(int numCards){
  moveFeedNumber = numCards;
}
void Player::setWarFlag(bool w)
{
  warFlag = w;
}
void Player::setHunger(int h)
{
  hunger = h;
}
void Player::freeAllVassals()
{
  for(int freed = 0; freed < vassals.size(); ++freed)
  {
    vassals.at(freed)->setOwner(NULL);
  }
  vassals.clear();
}


//functional
void Player::addVassal(Player* newVassal)
{
  vassals.push_back(newVassal);
}

void Player::feedVassal(Player* vassal, int numberOfCards)
{
  army.transfer(numberOfCards, vassal->getArmy());
}

void Player::feedAllVassals()
{
  if(ai == NULL)
  {
    for(int i = 0; i < vassals.size(); i++){
      feedVassal(vassals.at(i), vassals.at(i)->getHunger());
      vassals.at(i)->setHunger(0);
    }
  }
  else
  {
    for(int i = 0; i < vassals.size(); i++){
      feedVassal(vassals.at(i), ai->feedHowMuch(vassals.at(i)));
    }
  }
}

void Player::refillHand()
{
  army.transfer(maxHandSize-hand.size(), &hand);
}
